//
//  BaseTableViewController.swift
//  MicroBlog
//
//  Created by QT on 15/7/28.
//  Copyright © 2015年 綦敦涛. All rights reserved.
//


/// 添加所有模块控制器的BaseTableViewController，根据用户是否已  登录  创建不同view显示不同内容。



import UIKit

class BaseTableViewController: UITableViewController , VisitorLoginViewDelegate{
    
    var userLog = UserAccount.userLogon
    
    var vistorView: VisitorLoginView?
    
    
    var testView: NSObject?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }

    override func loadView() {
        userLog ?super.loadView() : setVisitorView()
    }
    
    
    /**
    设置“访客”视图
    */
    private func setVisitorView(){
        vistorView = VisitorLoginView()
        
        /**
        当用户没有登录，需要显示访客视图，所有继承此根控制器（BaseTableViewController）的控制器创建时
        都会有自己的vistorView，调用vistorView的setUpInfo方法就可以设置各自的访客视图
        */
        
        vistorView?.delegate = self
        // 记录VisitorLoginView
        view = vistorView
//        view.backgroundColor = UIColor.whiteColor()
        
        // 添加注册，登录按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorLoginViewWillRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorLoginViewWillLogin")
    }
    
    // 代理方法
    func visitorLoginViewWillRegister() {

        
    }
    func visitorLoginViewWillLogin() {
        let nav = UINavigationController(rootViewController: oauthViewController())

        presentViewController(nav, animated: true, completion: nil)
    }
    
    func cancel(){
        print("cancel")
    }
    
}
